package leetcode.code1461;

public class Solution {
	public boolean hasAllCodes(String s, int k) {
		int size = 1 << k;
		boolean[] hash = new boolean[size];
		int limit = (1 << k) - 1;
		int cnt = 0, num = 0;
		for (int i = 0; i < s.length(); i++) {
			int c = s.charAt(i) - '0';
			num <<= 1;
			num |= c;
			if (i >= k - 1) {
				num = num & limit;
				if (!hash[num]) {
					hash[num] = true;
					cnt++;
				}
			}
		}
		return cnt == size;
	}
}
